$('document').ready(function(){	

	$('#frmAdd').validate({
            errorClass      : 'error',
            errorElement	: 'span',
    		onfocusout		: false,
    		onkeyup			: false,
    		ignore			: 'input[type="text"]:hidden',
			rules:{
				playerid:{
					required:true,
					
				},
				pnationality:{
					required:true,
					
				},
				pleague:{
					required:true,
					
				},
				pclubid:{
					required:true,
					
				},
				pcategoryid:{
					required:true,
					
				},
				pfrom:{
					required:true,
					
				},
				pto:{
					required:true,
					
				},
			},
			messages:{
				playerid:{
					required:field_required,
					
				},
				pnationality:{
					required:select_required,
				},
				pleague:{
					required:select_required,
					
				},
				pclubid:{
					required:select_required,
					
				},
				pcategoryid:{
					required:select_required,
					
				},
				pfrom:{
					required:select_required,
					
				},
				pto:{
					required:select_required,
					
				},
			},
			errorPlacement: function(error, element) {
			       error.insertAfter(element); // change this to place error message elsewhere
			}	
	});
	
	$('.autoload').change(function(){ loadContract(); });	
});

function loadContract() {
	national = $('#pnationality').val();
	league = $('#pleague').val();
	if(national.length > 0 && league.length > 0){
		$.ajax({
			url:HOST_BACKEND+'ajax/contract',
			type:'POST',
			data:{n:national,l:league},
			success:function(data){
				if(data){
					data = JSON && JSON.parse(data) || $.parseJSON(data);
					$('#pclubid').html('');
					option='';
					$.each(data, function(key, value){						
						option = option+'<option value="'+value.id+'">'+ value.name+'</option>';
					});
					$('#pclubid').html(option);
				}
			},
			error:function(){}
		});
	}
}


